package cn.sinjet.carassist;

import com.mgroup.wazehelper.R;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import cn.sinjet.model.carassist.AppModel;
import cn.sinjet.viewmodel.ViewModel;

public class DialogView {
	Context context;
	
	public DialogView(Context context){
		this.context = context;
	}
    boolean handleView(int id){
    	switch(id){
    	case R.id.navi_set_day_night_mode:
    		showDayNightMode();
    		return true;
    	case R.layout.layout_password_dialog:
          	showPasswordPannel();	
    		break;
    	}
    	return false;
    }
    private void showDayNightMode(){
//		Log.d("test", "showDayNightMode");
	    int curMode = AppModel.getInstance().getDayNightMode();
		new AlertDialog.Builder(context).setTitle("导航模式选择")
		.setIcon(null)
		.setSingleChoiceItems(new String[] { "自动模式", "日间模式","夜间模式"}, curMode,
			     new DialogInterface.OnClickListener() {
			      public void onClick(DialogInterface dialog, int which) {
//			    	       Log.d("test", "select:"+which);
			    	       AppModel.getInstance().setDayNightMode(which);
			    	       refreshDayNightMode(which);
			              dialog.dismiss();
			      }})
	    .setNegativeButton("取消", null).show();
	}
	
	
	private void refreshDayNightMode(int index){
		Resources res = context.getResources();
		String[] dayNightMode = new String[]{res.getString(R.string.auto_mode),
				res.getString(R.string.day_mode),res.getString(R.string.night_mode)};
		if(index<3)
			ViewModel.getIns().setViewProperty(R.id.navi_set_day_night_mode_value, dayNightMode[index]);
	}
   
	PasswordPannel  pp = null;
	   void showPasswordPannel(){
		   if(pp == null)
			   pp = new PasswordPannel(context, R.style.CustomDialog);
		   pp.show();
	   }
 }
